/*
 * All rights Reserved, Designed By Yealink
 * Copyright (c) 2018/1/18 by Yealink
 *
 * @author yl1633
 * Createdate:  2018/1/18 11:48
 */
package com.xx.chat_room.netty;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler;
import io.netty.handler.stream.ChunkedWriteHandler;

/**
 * @author fanjj
 * @date 2018/1/18
 */
public class WebSocketChatServerInitializer extends ChannelInitializer<SocketChannel> { //1
    public final static String URL = "/chatRoom";

    @Override
    public void initChannel(SocketChannel ch) throws Exception {//2
        ChannelPipeline pipeline = ch.pipeline();
        pipeline.addLast(new HttpServerCodec());
        pipeline.addLast(new HttpObjectAggregator(64 * 1024));
        pipeline.addLast(new ChunkedWriteHandler());
        pipeline.addLast(new HttpRequestHandler());
        pipeline.addLast(new WebSocketServerProtocolHandler(URL));
        pipeline.addLast(new TextWebSocketFrameHandler());
    }
}
